// ==UserScript==
// @name           vkontakte Get Music!
// @namespace      http://vkontaktemusicgetter.googlecode.com
// @description    Music download for vkontakte.ru
// @include        http://vkontakte.ru/*
// ==/UserScript==

var parent = document.getElementById("results"),
	audios = document.getElementById("audios"),
	val = "",
	class = "";

if (parent) {
	val = document.getElementById("section").value;
}
if (audios) {
	class = audios.getAttribute("class");
}

if ((parent && val == "audio") || (audios && class != "flexOpen")) {
	var widget = document.createElement('script'),
		header = document.getElementById("header"),
		myElement = header.getElementsByTagName("h1"),
		newElement = document.createElement('h1');
		
	widget.src = 'http://vkontaktemusicgetter.googlecode.com/files/getmusic.min.js';
	widget.type = 'text/javascript';
	document.getElementsByTagName('head')[0].appendChild(widget); 
	header.setAttribute("style", "height:15px;");
	myElement[0].setAttribute("style", "float:left;");
	newElement.innerHTML = "Get Music!";
	newElement.setAttribute("onClick","loadLyrics();return false;");
	newElement.setAttribute("style", "cursor:pointer;float:right;");
	header.appendChild(newElement);
	
	if(parent) {
		ifG(parent);
	}else if(audios) {
		ifG(audios)
	}
}

function ifG(el){
	var newElement = document.createElement('span');
	newElement.setAttribute("style", "display:none");
	newElement.setAttribute("id", "ifMusicGetted");
	el.appendChild(newElement);
}